package com.future.taskdemo.k8s;

import io.kubernetes.client.openapi.ApiClient;
import io.kubernetes.client.util.ClientBuilder;
import io.kubernetes.client.util.credentials.AccessTokenAuthentication;

public class K8sManager {

    public static ApiClient getApiClient() {

        String master = "http://47.93.119.227:6443";
        String oauthToken = "eyJhbGciOiJSUzI1NiIsImtpZCI6IjR4NUJGd3I0aDl2ZWxyXzVYUUxJRUlfaGVqZjJtYXIxNUJsYV9SUC1hamMifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJuYW1lc3BhY2UtY29udHJvbGxlci10b2tlbi1oNWJocCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50Lm5hbWUiOiJuYW1lc3BhY2UtY29udHJvbGxlciIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50LnVpZCI6IjA1ZTgzYzYwLTBiZGItNDJkNi04ZjI1LWMzZWI2N2UwZjNiMCIsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDprdWJlLXN5c3RlbTpuYW1lc3BhY2UtY29udHJvbGxlciJ9.alFN6jbknxdy0JEvVnIiUvhsyh58WerTth1DflZcEJbqk_nvcxziSXVUMunlP09kUiJMjsnozEcwey9Qz8LJlaMxkiAvYOIuJqRPUU9j1_4s3R3JK08dNBj7FWCqNQwNuPl-VMLjcd3YkeMjGViS3RadFbQBv8TzfdfwF2tMmKpSPBQs4BxRiY275GdtTSWH2fJQdQRYmq-MV4HGBLv9jE2nZR7ru-ILtBLu3WyNPJbZVKA7U_4EKJVDsTZc3ejGkCKpj5SCbrgPy412E0wf6fo-bENBlRAcP744mCYU2g30JceGh_wMZ7J-uwCin6EoVI6hdPJl6ONnPZgHVdqoZg";

        ApiClient apiClient = new ClientBuilder()
                //设置 k8s 服务所在 ip地址
                .setBasePath(master)
                //是否开启 ssl 验证
                .setVerifyingSsl(false)
                //插入访问 连接用的 Token
                .setAuthentication(new AccessTokenAuthentication(oauthToken))
                .build();
        io.kubernetes.client.openapi.Configuration.setDefaultApiClient(apiClient);
        return apiClient;
    }

}
